package com.designpatterns.concretevisitor;

import java.util.Collection;
import java.util.Iterator;

import com.designpatterns.concreteelement.FloatElement;
import com.designpatterns.concreteelement.StringElement;
import com.designpatterns.element.Visitable;
import com.designpatterns.visitor.Visitor;

/**
 * ConcreteVisitor Class Implements {@link Visitor}
 * 
 * @author Haiqi.Wang
 * @since 2013-7-1下午3:16:21
 */
public class ConcreteVisitor implements Visitor {

	@Override
	public void visitString(StringElement stringE) {
		System.out.println(stringE.getSe());
	}

	@Override
	public void visitFloat(FloatElement floatE) {
		System.out.println(floatE.getFe());
	}

	@Override
	public void visitCollection(Collection<?> collection) {
		Iterator<?> iterator = collection.iterator();
		while (iterator.hasNext()) {
			Object o = (Object) iterator.next();
			if (o instanceof Visitable) {
				((Visitable)o).accept(this);
			}
		}
	}

}
